package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.travelstandard.entity.db.MbTravelStandCarCity;
import com.corpgovernment.travelstandard.mapper.MbTravelStandCarCityMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Slf4j
@Service
public class MbTravelStandCarCityService {

    @Autowired
    private MbTravelStandCarCityMapper mbTravelStandCarCityMapper;

    public List<MbTravelStandCarCity> selectByTsid(String tsId, String tsType) {
        Example example = new Example(MbTravelStandCarCity.class);
        example.createCriteria().andEqualTo("tsid", tsId).andEqualTo("tsType", tsType);
        return mbTravelStandCarCityMapper.selectByExample(example);
    }

    public List<MbTravelStandCarCity> selectByTsids(List<Long> tsIds, String tsType) {
        Example example = new Example(MbTravelStandCarCity.class);
        example.createCriteria().andIn("tsid", tsIds).andEqualTo("tsType", tsType);
        return mbTravelStandCarCityMapper.selectByExample(example);
    }

    public boolean saveBatch(List<MbTravelStandCarCity> carCityList) {
        if (CollectionUtils.isEmpty(carCityList)) {
            return false;
        }
        int result = mbTravelStandCarCityMapper.insertList(carCityList);
        return result > 0;
    }

    public boolean delByTsid(String tsId, String tsType) {
        Example example = new Example(MbTravelStandCarCity.class);
        example.createCriteria().andEqualTo("tsid", tsId).andEqualTo("tsType", tsType);
        int result = mbTravelStandCarCityMapper.deleteByExample(example);
        return result > 0;
    }
}
